<template>
    <van-sticky>
        <van-nav-bar title="购物车" left-text="返回" left-arrow @click-left="onClickLeft" />
    </van-sticky>


    <!-- <div>
        <div v-for="(item, index) in cartList">
            <div>
                <van-checkbox v-model="item.check" @click="intery"></van-checkbox>
            </div>

            <div>
                <van-card :num="item.num" :price="item.goods_price" :title="item.goods_name"
                    :thumb="item.goods_small_logo">
                    <template #footer>
                        <van-button @click="delCart(item, index)" size="mini">-</van-button>
                        <van-button @click="addCart(item)" size="mini">+</van-button>
                    </template>
                </van-card>
            </div>
            
        </div>
        <van-submit-bar :price="allPrice" :button-text="`结算(${allCount})`" @submit="onSubmit" class="xia">
            <van-checkbox v-model="allCheck" @click="allCheckFn">全选</van-checkbox>
        </van-submit-bar>
    </div> -->

    <van-card
  num="2"
  price="2.00"
  desc="描述信息"
  title="商品标题"
  thumb="https://fastly.jsdelivr.net/npm/@vant/assets/ipad.jpeg"
>
  <template #tags>
    <van-tag plain type="primary">标签</van-tag>
    <van-tag plain type="primary">标签</van-tag>
  </template>
  <template #footer>
    <van-button size="mini">按钮</van-button>
    <van-button size="mini">按钮</van-button>
  </template>
</van-card>
<van-submit-bar :price="3050" button-text="提交订单" @submit="onSubmit" class="xia">
  <van-checkbox v-model="checked">全选</van-checkbox>

</van-submit-bar>

</template>

<script setup>
import axios from 'axios';
import { ref } from 'vue';
import _ from 'lodash'
import { useRouter, useRoute } from 'vue-router';
const router = new useRouter();
const route = new useRoute();
const onClickLeft = () => history.back();
import { showConfirmDialog, showToast } from 'vant';

import { useCartStore } from '../../store';
import { storeToRefs } from 'pinia';
const { ADD_CART_ITEM, DEL_CART_ITEM, ALL_CHECK } = useCartStore();
const { allCount, allPrice, cartList } = storeToRefs(useCartStore());


const addCart = _.debounce((item) => {
    ADD_CART_ITEM(item)
}, 100)

const delCart=_.debounce((item,index)=>{
    if(item.num==1){
        showConfirmDialog({
            title:'删除',
            message:`确定要删除${item.goods_name}吗?`
        }).then(()=>{
            DEL_CART_ITEM(index)
        }).catch(()=>{
            showToast('取消删除')
        })
    } else{
        DEL_CART_ITEM(item)
    }
})

// const intery=()=>{
//     allCheck.value=cartList.value.every(item=>item.check)
// } 

const allCheck=ref(true)
// intery()

const allCheckFn=()=>{
    ALL_CHECK(allCheck.value)
}

const onSubmit=()=>{
       router.push('/Order') 
}
</script>




<style lang="scss" scoped>
.xia {
    margin-bottom: 50px;
}
</style>